const NewsModel = require("../../bin/models/NewsModel")

const NewsService = {
    add : async ({title,content,cover,editTime,category,isPublish})=>{
        return NewsModel.create({
            title,content,cover,editTime,category,isPublish
        })
    },

    getList:async ({_id})=>{
        return _id ? NewsModel.find({_id}) : NewsModel.find({})
    },

    publish:async ({_id,isPublish,editTime})=>{
        return NewsModel.updateOne({_id},{
            isPublish,
            editTime
        })
    },

    delList:async ({_id})=>{
        return NewsModel.deleteOne({
            _id
        })
    },

    updateList:async ({ _id,title,content,cover,editTime,category,isPublish})=>{
        if(cover){
            return NewsModel.updateOne({_id},{title,content,cover,editTime,category,isPublish})
        }else{
            return NewsModel.updateOne({_id},{title,content,editTime,category,isPublish})
        }
    }
}

module.exports = NewsService